package com.demo.service.impl;

import com.demo.entity.Sale;
import com.demo.repository.SaleRepo;
import com.demo.util.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author lepdou 2017-06-18
 */
@Service
public class SaleServiceImpl {

    @Autowired
    private SaleRepo saleRepo;

    @Transactional
    public void save(List<Sale> sales) {
        String createDate = sales.get(0).getCreateDate();
        saleRepo.deleteByCreateDate(createDate);



        saleRepo.save(sales);
    }

    public List<Sale> find(String house, int offset) {
        String beginDate = DateUtils.getDateOffset(-offset);
        System.out.println(house);
        return saleRepo.search(house, beginDate);
    }
}
